<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mobile_Expert_module extends CI_Module
{
    public $data;
    private $sid ;
    public function __construct()
    {
        parent::__construct();
        $this->sid = $GLOBALS['sid'];
        $this->data = $GLOBALS['config'];
        $this->load->model('member.User_model');
        $this->load->model('expert.Expert_model');
        $this->load->model('admin.Adminuser_model');
    }

    public function index()
    {
        $t = $this->db->dbprefix('admin_user');
        $sid = $this->sid ;
        $keyword = $where = '';
        if(!empty($_GET['keyword'])){
            $keyword = addslashes($_GET['keyword']);
            $where = "";
        }

        $pagesize = 10;
        $page = !empty($_GET['page']) && $_GET['page']>0 ? intval($_GET['page']) : 1;
        $where = array($t.'.is_open'=>'1');
        $result = $this->Expert_model->_list($where,$pagesize,$page,'1');
        $this->data['datalist'] = $result['list'];
        foreach ($this->data['datalist'] as $k => $v)
        {
            $this->data['datalist'][$k]['file_url']  = URLPIC.$v['avatar'];
            $this->data['datalist'][$k]['link']      = site_url('mobile/member/card/?eid='. $v['id']);
        }

        foreach($this->data['datalist'] as $k => $v)
        {
            if(empty($v['realname']))
            {
                unset($this->data['datalist'][$k]);
            }
        }
        $this->data['keyword'] = $keyword;
        $this->data['page'] = $page;
        $city = $this->data['sitecityname'];
        $this->data['common'] = array(
            array(
                'head'   => '达人列表' . ($keyword ? '-'.$keyword : $keyword),
                'title'   => $city.'旅游达人_旅游攻略_户外达人_2014_'.$city.'旅游网',
                'keywords'   => $city.'旅游达人,'.$city.'户外达人',
                'description'   => $city.'旅游达人，'.$city.'旅游网旅游达人频道数千名旅游达人，旅游专家，导游与您分享旅游景点，美食，购物，攻略信息。'
            )
        );
        if(!empty($_GET['isajax']))
        {
            header('Content-type:application/json;charset=utf-8');
            echo json_encode(array_values($this->data['datalist']));
            exit;
        }
        else
        {
            $this->load->view(MOBILE_TEMPLATE_NAME.'/'.'expert', $this->data);
        }
    }


    public function profile()
    {
        $id = intval($_GET['id']);
        $this->data['info'] = $this->Expert_model->_expert_info($id);
        $city = $this->data['sitecityname'];
        $this->data['common'] = array(
            array(
                'head'   => $this->data['info']['realname'],
                'title'   => $this->data['info']['realname'],
                'keywords'   => $this->data['info']['realname'],
                'description'   => $this->data['info']['realname'].'，'.$this->data['info']['profile'].','.$city.'旅游网'
            )
        );
        $this->load->view(MOBILE_TEMPLATE_NAME.'/'.'expert_profile', $this->data);
    }
}